﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.IO;
using haber.classes;

namespace haber
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            TimerStarter.StartTimer();
            Application["OnlineUsers"] = 0;
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            //HttpContext.Current.Application["OnlineUsers"] = 0;
            Application.Lock();

            Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
            using (dcHaberDataContext dc = new dcHaberDataContext())
            {
                Sayac s = new Sayac();
                s.IP = statics.ipAdresiGetir();
                dc.Sayacs.InsertOnSubmit(s);
                dc.SubmitChanges();
                s = null;
            }
            Application.UnLock();
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            Application.Lock();

            Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;

            Application.UnLock();
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}